package A1_回溯;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class LC_90子集II {
    LinkedList<Integer> path=new LinkedList<>();
    List<List<Integer>> result=new ArrayList<>();
    public List<List<Integer>> subsetsWithDup(int[] nums) {
        Arrays.sort(nums);
        int[] used=new int[nums.length];
        backtracking(nums,0,used);
        return result;
    }
    public void backtracking(int[] nums,int startIndex,int[] used){
        result.add(new ArrayList<>(path));
        for(int i=startIndex;i<nums.length;i++){
            if(i>0 && nums[i]==nums[i-1] && used[i-1]==0)
                continue;
            used[i]=1;
            path.add(nums[i]);
            backtracking(nums,i+1,used);
            path.removeLast();
            used[i]=0;
        }
        return;
    }
}
